package com.zhangdi.zddemo.zookeeper;

import org.apache.zookeeper.AddWatchMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

public class ZKConnection {
    private ZooKeeper zk;
    public ZooKeeper connector(String host) throws IOException, InterruptedException {
        zk = new ZooKeeper(host, 5000, new DistConfiguration());

        return zk;
    }

    public void close(){
        if(null != zk){
            try {
                zk.close();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
